using System;
using System.Collections.Generic;
using Commons.Utils;

namespace Commons.Models.Scores
{
	public delegate bool ComparePeriods(DateTime time1, DateTime time2);

	[Serializable]
	public class Periodicity
	{
		protected static Dictionary<string, Periodicity> register = new Dictionary<string, Periodicity>();

		public readonly ComparePeriods IsSamePeriod;

		public string Name { get; private set; }

		protected Periodicity(string name, ComparePeriods IsSamePeriod)
		{
			this.Name = name;
			this.IsSamePeriod = IsSamePeriod;

			register.Add(name, this);
		}

		public static Periodicity GetByName(string name)
		{
			return register.ContainsKey(name) ? register[name] : null;
		}

		public override string ToString()
		{
			return Name;
		}

		public static Periodicity Daily = new Periodicity("DAILY", DateTimeHelper.IsSameDay);
		public static Periodicity Weekly = new Periodicity("WEEKLY", DateTimeHelper.IsSameWeek);
		public static Periodicity Monthly = new Periodicity("MONTHLY", DateTimeHelper.IsSameMonth);
	}
}

